<?php
/**
 * A upload base system
 * @author Can.Nguyen
 */
class CMS_Upload
{

    public static function uploadProjectImage(Zend_Form_Element_File $file)
    {
        if (! $file->isUploaded ())
            return null;
        
        $fileInfo = pathinfo ( $file->getFileName () );
        $file->addFilter ( 'Rename', array ('target' => "public/data/projects/" . Zend_Date::now ()->toValue () . rand(0,1000) . "." . $fileInfo ['extension'], 'overwrite' => true ) );
        $file->receive ();
        return $file->getFileName ( null, false );
    }

    public static function uploadTopicImage(Zend_Form_Element_File $file)
    {
        if (! $file->isUploaded ())
            return null;
        
        $fileInfo = pathinfo ( $file->getFileName () );
        $file->addFilter ( 'Rename', array ('target' => "public/data/topic/" . Zend_Date::now ()->toValue () . rand(0,1000)  . "." . $fileInfo ['extension'], 'overwrite' => true ) );
        $file->receive ();
        return $file->getFileName ( null, false );
    }

    public static function uploadPlanImage(Zend_Form_Element_File $file)
    {
        if (! $file->isUploaded ())
            return null;
        
        $fileInfo = pathinfo ( $file->getFileName () );
        $file->addFilter ( 'Rename', array ('target' => "public/data/plan/" . Zend_Date::now ()->toValue () . rand(0,1000)  . "." . $fileInfo ['extension'], 'overwrite' => true ) );
        $file->receive ();
        return $file->getFileName ( null, false );
    }
	
	public static function uploadSponsor(Zend_Form_Element_File $file)
	{
		if (! $file->isUploaded ())
            return null;
        
        $fileInfo = pathinfo ( $file->getFileName () );
        $file->addFilter ( 'Rename', array ('target' => "public/data/sponsor/" . Zend_Date::now ()->toValue () . rand(0,1000)  . "." . $fileInfo ['extension'], 'overwrite' => true ) );
        $file->receive ();
        return $file->getFileName ( null, false );
	}
	
	public static function uploadFlash(Zend_Form_Element_File $file)
	{
		if (! $file->isUploaded ())
            return null;
        
        $fileInfo = pathinfo ( $file->getFileName () );
        $file->addFilter ( 'Rename', array ('target' => "public/data/flash/" . Zend_Date::now ()->toValue () . rand(0,1000)  . "." . $fileInfo ['extension'], 'overwrite' => true ) );
        $file->receive ();
        return $file->getFileName ( null, false );
	}
}